package com.wgts.wgts.mvp.model.imp;

import com.wgts.wgts.mvp.model.IMyCenterFragmentModel;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.NetService;
import com.wgts.wgts.netmodle.resp.AppUpdateEntity;
import com.wgts.wgts.netmodle.resp.MyCenterMessageEntity;
import com.wgts.wgts.rxjava.MVPResultSubscriber;
import com.wgts.wgts.tools.AppInfor;

import rx.Subscriber;

/*
 *
 *
 *   data:2018/9/2918:54
 *
 */public class MyCenterFragmentModel implements IMyCenterFragmentModel {
     private NetService netService;

    public MyCenterFragmentModel(NetService netService) {
        this.netService = netService;
    }

    @Override
    public void getMyCenterResult(HttpResultSubscriber<MyCenterMessageEntity> subscriber) {
        netService.myCenterMessage(subscriber);
    }

    @Override
    public void quitLogin(MVPResultSubscriber<String> subscriber) {
        rx.Observable.create(new rx.Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                AppInfor.getInstance().setRefreshToken("");
                AppInfor.getInstance().setAccessToken("");
                AppInfor.getInstance().setUserYQCode("");
                AppInfor.getInstance().setInviteCode("");
                AppInfor.getInstance().setUserName("");
                AppInfor.getInstance().setUserState(0);
                subscriber.onNext("success");

            }
        }).subscribe(subscriber);
    }

    @Override
    public void appUpdate(String channel, String version, HttpResultSubscriber<AppUpdateEntity> subscriber) {
        netService.appUpdate(channel, version, subscriber);
    }
}
